import express from "express";
import { ExpressPeerServer } from "peer";

const app = express();
const customGenerationFunction = () =>
  (Math.random().toString(36) + "0000000000000000000").substring(2, 16);

const server = app.listen(9000, () => {
  console.log("server is listening on port:9000");
});

const peerServer = ExpressPeerServer(server, {});

peerServer.on("connection", (client) => {
  console.log("连接上了", client.getId());
  // 可以向客户端发送消息
  client.send("hello");
});
app.use("/peerjs", peerServer);
app.get("/", (req, res, next) => res.send("Hello world!"));
